package com.itheima.day20.demo06;

import java.io.*;

/**
 * 1. 复制图片, 或者视频.		//要求, 用4种方法实现.
 * 1. 普通的字节流一次读写一个字节.
 * 2. 普通的字节流一次读写一个字节数组.
 * <p>
 * 3. 高效的字节流一次读写一个字节.				//必须掌握.
 * 4. 高效的字节流一次读写一个字节数组.
 */
public class demo01 {
    public static final String SRC = "./homework/src/com/itheima/day20/demo06/a.txt";
    public static final String DEST = "./homework/src/com/itheima/day20/demo06/c.txt";

    public static void main(String[] args) throws Exception {
        //1. 普通的字节流一次读写一个字节.
        //method1();
        //2. 普通的字节流一次读写一个字节数组.
        //method2();
        //3. 高效的字节流一次读写一个字节.
        //method3();
        method4();

        //4. 高效的字节流一次读写一个字节数组.


    }

    public static void method4() throws IOException {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(SRC)));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(DEST)));
        int len = 0;
        byte[] bys = new byte[1024];
        while ((len = bis.read(bys)) != -1) {
            bos.write(bys, 0, len);
        }
        bos.close();
        bis.close();
    }

    public static void method3() throws IOException {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(SRC)));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(DEST)));
        int len = 0;
        while ((len = bis.read()) != -1) {
            bos.write(len);
        }
        bos.close();
        bis.close();
    }

    public static void method2() throws IOException {
        FileInputStream fis = new FileInputStream(SRC);
        FileOutputStream fos = new FileOutputStream(DEST);
        int len = 0;
        byte[] bys = new byte[1024];
        while ((len = fis.read(bys)) != -1) {
            fos.write(bys, 0, len);
        }
        fos.close();
        fis.close();
    }

    public static void method1() throws IOException {
        FileInputStream fis = new FileInputStream(SRC);
        FileOutputStream fos = new FileOutputStream(DEST);
        int len = 0;
        while ((len = fis.read()) != -1) {
            fos.write(len);
        }
        fos.close();
        fis.close();
    }
}
